{# Copyright The IETF Trust 2015-2022, All Rights Reserved #}
{% load origin %}
{% load static %}
{% load textfilters tz %}
{% origin %}
{% with item=session.official_timeslotassignment acronym=session.group_at_the_time.acronym %}
    {% if session.agenda and show_agenda %}
        {# Note: if called with show_agenda=True, calling template must load agenda_materials.js, needed by session_agenda_include.html #}
        {% include "meeting/session_agenda_include.html" with slug=item.slug session=session timeslot=item.timeslot only %}
    {% endif %}
    <div role="group" class="btn-group btn-group-sm">
        {% if session.agenda and show_agenda %}
            {# agenda pop-up button #}
            <a class="btn btn-outline-primary"
               data-bs-toggle="modal"
               data-bs-target="#modal-{{ item.slug }}"
               aria-label="Show meeting materials"
               title="Show meeting materials">
                <i class="bi bi-arrows-fullscreen"></i>
            </a>
            {# materials tar file #}
            <a class="btn btn-outline-primary"
               href="{% url 'ietf.meeting.views.session_draft_tarfile' num=meeting.number acronym=acronym %}"
               aria-label="Download meeting materials as .tar archive"
               title="Download meeting materials as .tar archive">
                <i class="bi bi-file-zip"></i>
            </a>
            {# materials PDF file #}
            <a class="btn btn-outline-primary"
               href="{% url 'ietf.meeting.views.session_draft_pdf' num=meeting.number acronym=acronym %}"
               aria-label="Download meeting materials as PDF file"
               title="Download meeting materials as PDF file">
                <i class="bi bi-file-pdf"></i>
            </a>
        {% endif %}
        {# notes #}
        {% if session.agenda.uses_notes %}
            <a class="btn btn-outline-primary"
               href="{{ session.notes_url }}"
               aria-label="Notepad for note-takers"
               title="Notepad for note-takers">
                <i class="bi bi-journal-text"></i>
            </a>
        {% endif %}
        {# show stream buttons up till end of session, then show archive buttons #}
        {% if now < item.timeslot.end_time %}
            {# Chat #}
            <a class="btn btn-outline-primary"
               href="{{ session.chat_room_url }}"
               aria-label="Chat for {{ session.chat_room_name }}"
               title="Chat for {{ session.chat_room_name }}">
                <i class="bi bi-lightbulb"></i>
            </a>
            {# Remote call-in #}
            {% if session.agenda_note|first_url|conference_url %}
                <a class="btn btn-outline-primary"
                   href="{{ session.agenda_note|first_url }}"
                   aria-label="Online conference"
                   title="Online conference">
                    <i class="bi bi-people"></i>
                </a>
            {% elif session.remote_instructions|first_url|conference_url %}
                <a class="btn btn-outline-primary"
                   href="{{ session.remote_instructions|first_url }}"
                   aria-label="Online conference"
                   title="Online conference">
                    <i class="bi bi-people"></i>
                </a>
            {% elif item.timeslot.location.webex_url %}
                <a class="btn btn-outline-primary"
                   href="{{ item.timeslot.location.webex_url|format:session }}"
                   aria-label="Webex session"
                   title="Webex session">
                    <i class="bi bi-people"></i>
                </a>
                {# Video stream (meetecho) #}
            {% elif session.video_stream_url %}
                <a class="btn btn-outline-primary"
                   href="{{ session.video_stream_url|format:session }}"
                   aria-label="Meetecho video stream"
                   title="Meetecho video stream">
                    <i class="bi bi-camera-video"></i>
                </a>
            {% else %}
                <a class="btn btn-outline-primary text-secondary disabled"
                   href="#"
                   aria-label="No online conference info found in remote instructions or agenda note"
                   title="No online conference info found in remote instructions or agenda note">
                    <i class="bi bi-people"></i>
                </a>
            {% endif %}
            {# iCalendar item #}
            <a class="btn btn-outline-primary"
               href="{% url 'ietf.meeting.views.agenda_ical' num=meeting.number session_id=session.id %}"
               aria-label="icalendar entry for {{ acronym }} session on {{ item.timeslot.time|utc|date:'Y-m-d H:i' }} UTC"
               title="icalendar entry for {{ acronym }} session on {{ item.timeslot.time|utc|date:'Y-m-d H:i' }} UTC">
                <i class="bi bi-calendar"></i>
            </a>
        {% else %}
            {# Chat logs #}
            <a class="btn btn-outline-primary"
               href="{{ session.chat_archive_url }}"
               aria-label="Chat logs for {{ session.chat_room_name }}"
               title="Chat logs for {{ session.chat_room_name }}">
                <i class="bi bi-file-text"></i>
            </a>
            {% with session.recordings as recordings %}
                {% if recordings %}
                    {# There's no guaranteed order, so this is a bit messy: #}
                    {# Audio #}
                    {% for r in recordings %}
                        {% with href=r.get_href %}
                            {% if 'audio' in href %}
                                <a class="btn btn-outline-primary"
                                   href="{{ href }}"
                                   aria-label="{{ r.title }}"
                                   title="{{ r.title }}">
                                    <i class="bi bi-file-play"></i>
                                </a>
                            {% endif %}
                        {% endwith %}
                    {% endfor %}
                    {# YouTube #}
                    {% for r in recordings %}
                        {% with href=r.get_href %}
                            {% if 'youtu' in href %}
                                <a class="btn btn-outline-primary"
                                   href="{{ href }}"
                                   aria-label="{{ r.title }}"
                                   title="{{ r.title }}">
                                    <i class="bi bi-file-slides"></i>
                                </a>
                            {% endif %}
                        {% endwith %}
                    {% endfor %}
                    {# Any other recordings #}
                    {% for r in recordings %}
                        {% with href=r.get_href %}
                            {% if not 'audio' in href and not 'youtu' in href %}
                                <a class="btn btn-outline-primary"
                                   href="{{ href }}"
                                   aria-label="{{ r.title }}"
                                   title="{{ r.title }}">
                                    <i class="bi bi-file-play"></i>
                                </a>
                            {% endif %}
                        {% endwith %}
                    {% endfor %}
                {% elif show_empty  %}
                    {# <i class="bi"></i> #}
                {% endif %}
                {% if session.session_recording_url %}
                    <a class="btn btn-outline-primary"
                       href="{{ session.session_recording_url }}"
                       aria-label="Meetecho session recording"
                       title="Meetecho session recording">
                        <i class="bi bi-file-slides"></i>
                    </a>
                {% endif %}
            {% endwith %}
        {% endif %}
    </div>
{% endwith %}
